package demo2;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * Creared with IntelliJ IDEA.
 * Description:
 * User:yxd
 * Date:2022-03-18
 * Time:18:33
 */
public class TestDelete {
    public static void main(String[] args) throws SQLException {
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setURL("jdbc:mysql://127.0.0.1:3306/ebook?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("123456");

        Connection connection = dataSource.getConnection();

        String sql = "delete from borrow_info where id = (select r.id from (select max(id) id from borrow_info) r);";

        PreparedStatement statement = connection.prepareStatement(sql);

        System.out.println(statement);

        System.out.println(statement.executeUpdate());

        statement.close();
        connection.close();
    }
}
